<template>
	<view class="page">
		<view class="con">
			<view class="uni-list" v-if="listData.length != 0">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item, key) in listData" :key="key" @click="goSampleDetail(key)">
				
					<view class="uni-media-list" v-if="item">
						<view class="width-100 uni-flex">
							<text class="width-a100">{{ item.common && item.common.title }}</text>
							<!-- <text class="width-auto date">{{ item.common && item.common.value && item.common.value.samplestart && item.common.value.samplestart.value }}</text> -->
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view v-if="listData.length != 0" v-for="(item, key) in listData" :key="key" >
			<uni-swipe-action >
				<view class="" @click="goSampleDetail(item, key,null)">
					<uni-swipe-action-item class="task" :options="options" @click="swipeClick($event, key)">
						<view class="cont">
							<text>{{ item.common && item.common.title }}</text>
							<text>{{ item.common && item.common.value && item.common.value.samplestart && item.common.value.samplestart.value }}</text>
						</view>
					</uni-swipe-action-item>
					
				</view>
			</uni-swipe-action>
			<view class="width-a100" style="padding: 10rpx;" v-show="item.show" >
				<text class="days" v-for="(items,keys) in item.sample_info.value" :key="keys"  @click="goSampleDetail(item, key,true)">
					第{{keys}}天
				</text>
			</view>
		</view> -->
	</view>
</template>
<script>

import net from '../../net.js';
import service from '../../service.js';
import utils from '../../common/utils.js';
import uploaddata from '../../uploaddata.js';

export default {

	data() {
		return {
			listData: {},
			data: {},
			loadingType: 0,
			isLogo :'',
			codeId:''
		};
	},
	// 加载数据
	onLoad(res) {
		console.log(res);
		this.codeId = res.codeId;
		this.isLogo = res.isLogo;
		if(this.isLogo == 'local'){
			let detail = service.getTaskDetail(this.codeId, null);
			this.listData = detail;
			console.log("---从本地",detail);
		}
		this.listData = [];
		this.loadingType = 0;
		this.data = JSON.parse(res.data);


		// 设置项目数据，用于上传
		uploaddata.setUploadItem(this.data);
	
		let detail = service.getTaskDetail(this.codeId, null);
		console.log(detail,"=============detail");
		//给detail中的每个值添加一个控制显示的属性值
		for(let i in detail){
			detail[i].show =false;
		}
		if (detail == null) {
			this.getList();
		} else {
			this.listData = detail;
		}
	

	},
	// 下拉刷新
	onPullDownRefresh() {
		this.loadingType = 0;
		this.listData = [];
		this.getList();
	},
	//页面显示刷新
	// onShow(){
	// 	this.loadingType = 0;
	// 	this.listData = [];
	// 	this.getList();
	// },
	methods: {
		//滑动按钮
		swipeClick(e, key) {
			let { content } = e;
			console.log(e);
			if (content.text === '隐藏') {
				this.listData[key].show = false;
			} else if (content.text === '显示') {
				this.listData[key].show = true;
			}
		},

		goSampleDetail( tableId) {
			console.log( tableId);
		
			let param = utils.toParam({ codeId: this.codeId, tableId: tableId });
			console.log(param);
			uni.navigateTo({
				url: './sampling_detail' + param
			});
		},
		getList() {
			if (this.loadingType != 0) {
				return;
			}

			if (this.codeId == null) {
				uni.showToast({ icon: 'none', title: '更新异常' });
				this.loadingType = 0;
				uni.stopPullDownRefresh();
				return;
			}

			this.loadingType = 1;

			net.netGet(
				'/module/api/main/getSampleInfoNew/' + encodeURIComponent(this.codeId),
				{},
				res => {
					console.log(res, 'res');

					if (res != null && Object.keys(res).length != 0) {
						this.listData = res;
						// 保存 this.codeId 的数据
						utils.exeMainCallBack({}, '');
						uni.showToast({ icon: 'none', title: '正在更新数据' });
					} else {
						utils.exeMainCallBack({}, '');
						this.listData = {};
						uni.showToast({ icon: 'none', title: '暂无数据' });
					}
					service.setTaskDetail(this.codeId, this.listData);
				},
				() => {
					uni.showToast({ icon: 'none', title: '无法更新数据' });
				},
				() => {
					this.loadingType = 0;
					uni.stopPullDownRefresh();
				}
			);
		},
		goItem(sitem, id, item, tableId) {
			let param = utils.toParam({ data: item, tableId: tableId, id: id, codeId: this.codeId });
			uni.navigateTo({
				url: './sampling_item' + param
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	padding-top: 20upx;
	height: auto;
	width: 100%;
}

page {
	background: #efeff4;
}

.task {
	.cont {
		padding: 12rpx;
		font-size: 38rpx;
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		height: 84rpx;
		line-height: 84rpx;
		// position: relative;
		background-color: #fff;
		border-bottom-color: #f5f5f5;
		border-bottom-width: 1px;
		border-bottom-style: solid;
	}
}
.days{
	border: 1rpx solid #0FAEFF;
	margin: 4rpx 10rpx;
	padding: 10rpx;
	// display: none;
}
.uni-list-cell:after {
	left: 0;
}

.uni-media-list-body {
	height: auto;
	justify-content: space-around;
}

.uni-media-list {
	flex-wrap: wrap;
}

.uni-list-cell text {
	margin: 0;
}

.width-100 {
	flex: 0 0 100%;
}

.date {
	font-size: 30upx;
	color: #666666;
	margin-left: 10upx;
}

.info-title {
	color: #353535;
	font-size: 33upx;
}

.item-con {
	flex-wrap: wrap;
}

.item-con .item {
	padding: 5px;
	border: 1px solid #555555;
	margin: 5px;
	font-size: 30upx;
	color: #555555;
}

.item-con .item:active {
	color: #ffffff;
	background: #007aff;
	border: 1px solid #007aff;
}
</style>
